﻿using System;
using System.Collections.Generic;
using System.Web;
using System.Web.UI;
using System.Web.UI.WebControls;
using System.Data;
using System.Collections.Specialized;

using Utils;

public partial class account_repass : FBasePage
{

    // Methods
    protected override void OnLoad(EventArgs e)
    {
        base.OnLoad(e);
    }

    protected void submit_ServerClick(object sender, EventArgs e)
    {
        string str = this.resetemail.Value;
        if (str == "")
        {
            this.SetError("邮箱不能为空！");
            base.Response.Redirect("repass.aspx");
        }
        string sitename = "";
        string str3 = "";
        string mailfrom = "";
        string mailhost = "";
        string mailuser = "";
        string mailpass = "";
        if (base.ASSystem != null)
        {
            sitename = base.ASSystem.sitename;
            mailfrom = base.ASSystem.mailfrom;
            mailhost = base.ASSystem.mailhost;
            mailuser = base.ASSystem.mailuser;
            mailpass = base.ASSystem.mailpass;
        }
        str3 = base.Request.Url.AbsoluteUri.Substring(7);
        str3 = "http://" + str3.Substring(0, str3.IndexOf('/'));
        string secret = "";
        string str9 = "";
        string s = "";
        Maticsoft.BLL.UserInfo info = new Maticsoft.BLL.UserInfo();
        string strWhere = "";
        strWhere = string.Format(" Email='{0}'", str);
        DataSet set = info.GetList(strWhere);
        if ((set != null) && (set.Tables.Count > 0))
        {
            if (set.Tables[0].Rows.Count > 0)
            {
                str9 = set.Tables[0].Rows[0]["Username"].ToString();
                s = set.Tables[0].Rows[0]["id"].ToString();
                secret = Helper.GetRandomString(0x20);
                info.UpdateSecret(int.Parse(s), secret);
                NameValueCollection values = new NameValueCollection();
                values.Add("username", str9);
                values.Add("sitename", sitename);
                values.Add("wwwprefix", str3);
                values.Add("recode", secret);
                string str12 = WebSiteHelper.LoadTemplate("~/template/mail_repass.html", values);
                string subject = base.ASSystem.sitename + "重设密码";
                string body = str12;
                List<string> toMails = new List<string>();
                toMails.Add(str);
                string error = string.Empty;
                if (base.SendMail(toMails, subject, body, out error))
                {
                    base.SetSuccess("邮件发送成功！");
                    base.Response.Redirect("repass.aspx");
                }
                else
                {
                    this.SetError("邮件发送失败！请检查SMTP设置");
                    base.Response.Redirect("repass.aspx");
                }
            }
            else
            {
                this.SetError("友情提示：此用户不存在");
            }
        }
    }


}